﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using OrganizedIN.BAL;
using OrganizedIN.BussinessServices;

namespace OrganizedIN.UI.AccountSetting
{
    public partial class UpdatePersonal : System.Web.UI.Page
    {
        BLL oibll = new BLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    fillUserinfo();
                }
            }
            catch (Exception ex)
            {
            }
        }

        private void fillUserinfo()
        {
            string username = Session["UserID"].ToString();
            UserRegistration objur = oibll.UserInformation(username);
            
             txtApproveEmail.Text = objur.ApproveEmail;
             txtEmail.Text = objur.UserEmailID;
             txtpassword.Text = objur.UserPassword;
             txtsecurity.Text = objur.SecurityAns;
             txtSecurityPin.Text = objur.SecurityPin;
             txttimezone.Text = objur.UserTimeZone;
             txttruncateEmail.Text = objur.TruncateEmailSub;
             txtusername.Text = objur.UserFname;
             drpglobalEmail.Text = objur.GlobalEmailoption;
        }

        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            try
            {
                BLL registerobj = new BLL();
                UserRegistration setdata = new UserRegistration();

                if (txtusername.Text != "" && txtEmail.Text != "" && txtpassword.Text != "")
                {
                    setdata.UserEmailID = txtEmail.Text;
                    setdata.UserFname = txtusername.Text;
                    setdata.UserPassword = txtpassword.Text;                    
                    setdata.UserTimeZone = txttimezone.Text;
                    setdata.UserEmailID = txtEmail.Text;
                    setdata.TruncateEmailSub = txttruncateEmail.Text;
                    setdata.SecurityAns = txtsecurity.Text;
                    setdata.GlobalEmailoption = drpglobalEmail.Text;
                    setdata.ApproveEmail = txtApproveEmail.Text;
                    setdata.SecurityPin = txtSecurityPin.Text;
                    registerobj.UserRegistrationUpdate(setdata);
                    clearAll();
                    Response.Redirect("PersonalSetting.aspx");
                   // lblerrmsg.Text = "Please fill the all fields properly";
                }
                else
                {
                    lblerrmsg.Text = "Please fill the all fields properly";
                }
            }
            catch (Exception ex)
            {
            }
        }
        private void clearAll()
        {
            txtApproveEmail.Text = "";
            txtpassword.Text = "";
            txtEmail.Text = "";
            txtsecurity.Text = "";
            txtSecurityPin.Text = "";
            txttimezone.Text = "";
            txttruncateEmail.Text = "";
            txtusername.Text = "";
            drpglobalEmail.Text = "";
            drpDeactivateAcct.Text = "";
        }

    }
}
